package Demo4;

import java.util.Scanner;

class TreeNode {
    public char val; //储存节点的值(这里指的是数值)
    public TreeNode left; //存储该节点的左孩子节点
    public TreeNode right; //存储该节点的右孩子节点

    //构造方法，被调用时把该节点初始化
    public TreeNode(char val) {
        this.val = val;
    }
}
public class Main{
     public static int i=0;
    public static void main(String[] args) {
        Scanner in=new Scanner(System.in);
        while (in.hasNextLine()){
            String str=in.nextLine(); //读取控制台输入的数据
            TreeNode root=createTree( str);//根据前序遍历，创建一棵二叉树
            inOrder(root); //把创建好的二叉树进行中序遍历

        }
    }
    public static TreeNode createTree(String str){
        char ch=str.charAt(i);
        TreeNode root=null;
        if (ch!='#'){
            root=new TreeNode(ch);
            i++;
            root.left=createTree(str);
            root.right=createTree(str);
        }
        else {
            i++;
        }
        return root;
    }
       public static void inOrder(TreeNode root){
        if (root==null){
            return;
        }
        inOrder(root.left);
           System.out.print(root.val+" ");
           inOrder(root.right);
       }
}

